<template>
  <div class="container-fluid">
    <!-- 顶部导航栏 -->
    <header class="col-md-12 bg-primary text-white p-3">
      <div class="row justify-content-between align-items-center">
        <div class="col-md-6">
          <h1>停车场管理系统</h1>
        </div>
        <div class="col-md-6 text-right">
          <span>{{ username }}</span>
          <router-link to="/parking/manage" class="btn btn-light ml-2">返回列表</router-link>
          <router-link to="/" class="btn btn-light ml-2">返回首页</router-link>
        </div>
      </div>
    </header>

    <!-- 主内容区域 -->
    <main class="col-md-12 mt-4">
      <div class="card">
        <div class="card-header bg-secondary text-white">
          <h2 class="text-center">添加车位</h2>
        </div>
        <div class="card-body">
          <form @submit.prevent="addParking">
            <div class="form-group">
              <label for="code">车位编号</label>
              <input 
                type="text" 
                class="form-control" 
                id="code" 
                placeholder="请输入车位编号" 
                v-model="parking.code"
                required
              >
            </div>
            <div class="form-group">
              <label for="type">车位类型</label>
              <select 
                class="form-control" 
                id="type" 
                v-model="parking.type"
                required
              >
                <option value="0">临时车位</option>
                <option value="1">固定车位</option>
              </select>
            </div>
            <div class="form-group">
              <label for="area">所属区域</label>
              <input 
                type="text" 
                class="form-control" 
                id="area" 
                placeholder="请输入所属区域" 
                v-model="parking.area"
              >
            </div>
            <div class="form-group">
              <label for="status">状态</label>
              <select 
                class="form-control" 
                id="status" 
                v-model="parking.status"
                required
              >
                <option value="0">空闲</option>
                <option value="1">占用</option>
                <option value="2">维护</option>
              </select>
            </div>
            <button type="submit" class="btn btn-primary">添加</button>
            <router-link to="/parking/manage" class="btn btn-secondary ml-2">取消</router-link>
          </form>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
export default {
  name: 'AddParkingView',
  data() {
    return {
      username: '',
      parking: {
        code: '',
        type: 0,
        status: 0,
        area: ''
      }
    }
  },
  mounted() {
    this.username = localStorage.getItem('username') || '管理员'
  },
  methods: {
    addParking() {
      // 模拟添加车位逻辑
      alert(`成功添加车位：${this.parking.code}`)
      // 跳转到车位管理页面
      this.$router.push('/parking/manage')
    }
  }
}
</script>

<style >
/* 这里可以添加组件特定的样式 */
</style>